#include <stdio.h>
#include <stdbool.h>

#define BOARD_SIZE 15

int board[BOARD_SIZE][BOARD_SIZE];  // 0-empty, 1-black, 2-white

// 检查胜利
bool check_win(int player) {
    // 遍历棋盘，检查每个位置
    for (int i = 0; i < BOARD_SIZE; i++) {
        for (int j = 0; j < BOARD_SIZE; j++) {
            if (board[i][j] == player) {
                // 检查水平、垂直、和对角线
                if (j + 4 < BOARD_SIZE && board[i][j + 1] == player && board[i][j + 2] == player &&
                    board[i][j + 3] == player && board[i][j + 4] == player) {
                    return true;
                }
                if (i + 4 < BOARD_SIZE && board[i + 1][j] == player && board[i + 2][j] == player &&
                    board[i + 3][j] == player && board[i + 4][j] == player) {
                    return true;
                }
                if (i + 4 < BOARD_SIZE && j + 4 < BOARD_SIZE && board[i + 1][j + 1] == player &&
                    board[i + 2][j + 2] == player && board[i + 3][j + 3] == player &&
                    board[i + 4][j + 4] == player) {
                    return true;
                }
                if (i - 4 >= 0 && j + 4 < BOARD_SIZE && board[i - 1][j + 1] == player &&
                    board[i - 2][j + 2] == player && board[i - 3][j + 3] == player &&
                    board[i - 4][j + 4] == player) {
                    return true;
                }
            }
        }
    }
    return false;
}

// 初始化棋盘
void init_board() {
    for (int i = 0; i < BOARD_SIZE; i++) {
        for (int j = 0; j < BOARD_SIZE; j++) {
            board[i][j] = 0;  // 0表示空
        }
    }
}

// 打印棋盘
void print_board() {
    for (int i = 0; i < BOARD_SIZE; i++) {
        for (int j = 0; j < BOARD_SIZE; j++) {
            if (board[i][j] == 1) {
                printf(" B ");
            } else if (board[i][j] == 2) {
                printf(" W ");
            } else {
                printf(" . ");
            }
        }
        printf("\n");
    }
}

int main() {
    init_board();
    print_board();

    // 模拟落子
    board[7][7] = 1;  // 黑子
    board[7][8] = 2;  // 白子
    print_board();

    // 检查胜利
    if (check_win(1)) {
        printf("黑方胜利！\n");
    } else if (check_win(2)) {
        printf("白方胜利！\n");
    } else {
        printf("游戏继续...\n");
    }

    return 0;
}

